﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreHelper.Validation.Validators
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
    public class EnumValidatorAttribute : BaseValidatorAttribute
    {
        public EnumValidatorAttribute(params object[] enumValues) : this(ValidationUtils.Messages.Enum, enumValues)
        {
        }
        public EnumValidatorAttribute(string errorMessage, params object[] enumValues) : base(errorMessage)
        {
            EnumValues = enumValues;
        }

        /// <summary>
        /// 可取的枚举值
        /// </summary>
        public object[] EnumValues { get; set; }

        public override bool IsValid(object value)
        {
            return EnumValues.Contains(value);
        }
    }
}
